package com.inspinia.base.common.exception;


import com.inspinia.base.common.model.NameCodeEnum;

/**
 * Created by frank_zhu on 2017/6/30.
 */
public enum ApiErrorCode implements NameCodeEnum {
    noPermission(10000,"用户无该接口权限"),
    keyExpired(10001,"key失效"),
    keyAuthenticationFailed(10002,"key认证失败"),
    userNotExist(10003,"用户不存在"),
    userNoDataAuthority(10004,"用户无该省市数据权限"),
    userStatusException(10005,"用户状态异常"),
    externalApiClose(10006,"接口已关闭"),
    externalApiParametersError(10007,"接口参数错误");

    private final int code;
    private final String name;

    ApiErrorCode(int code, String name){
        this.code=code;
        this.name=name;
    }

    @Override
    public int getCode() {
        return code;
    }

    @Override
    public String getName() {
        return name;
    }

    public static ApiErrorCode valueOf(int code) {
        for (ApiErrorCode apiErrorCode : values()) {
            if (apiErrorCode.code == code) {
                return apiErrorCode;
            }
        }
        return null;
    }

    public static ApiErrorCode nameOf(String name){
        for (ApiErrorCode apiErrorCode : values()) {
            if (apiErrorCode.name.equals(name)) {
                return apiErrorCode;
            }
        }
        return null;
    }
    }
